package action;

import java.util.ArrayList;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import biz.CartBiz;
import dao.ItemDAO;
import util.ActionForward;
import vo.Item;

public class ItemListAction implements Action{

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		///////오늘본 상품 로직 ::Cookie정보에 담긴 image들 불러오기 2)//////////////
		///////itemList.jsp에 마지막 view를 추가한다.3)
		ArrayList<String> images = new ArrayList<String>();
		Cookie[ ] cookies = request.getCookies();
		if(cookies != null){
			for(int i=0; i<cookies.length; i++){
				if(cookies[i].getName().startsWith("image")){
					images.add(cookies[i].getValue());
				}
			}
		}
		request.setAttribute("images", images);
		
		ItemDAO dao = ItemDAO.getInstance();
		ArrayList<Item> list=dao.getAllItems();
		request.setAttribute("list", list);
		
		ActionForward forward = new ActionForward();
		forward.setUrl("itemList.jsp");
		return forward;
	}

}
